package com.example.administrator.szb.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.InputType;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.szb.R;
import com.example.administrator.szb.activity.base.BaseActivity;
import com.example.administrator.szb.adapter.BaseAdapter;
import com.example.administrator.szb.bean.YWGLBean;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by D N on 2017/11/7.
 * 次级业务详情
 */

public class CJYWXQActivity extends BaseActivity {
    @Bind(R.id.ywxq_no_image_fh)
    ImageView ywxqNoImageFh;
    @Bind(R.id.ywxq_no_text_title)
    TextView ywxqNoTextTitle;
    @Bind(R.id.ywxq_no_recyclerview)
    RecyclerView ywxqNoRecyclerview;
    @Bind(R.id.ywxq_no_edit_xgms)
    EditText ywxqNoEditXgms;
    @Bind(R.id.ywxq_no_text_zs)
    TextView ywxqNoTextZs;
    @Bind(R.id.ywxq_no_xgms)
    LinearLayout ywxqNoXgms;
    @Bind(R.id.ywxq_no_button_bc)
    Button ywxqNoButtonBc;
    String title;
    YWGLBean ywbqglBean;

    ArrayList<YWGLBean.NextBeanX.NextBean> info = new ArrayList<YWGLBean.NextBeanX.NextBean>(){
        @Override
        public String toString() {
            String title = "";
            for (int i = 0; i < info.size(); i++) {
                if (info.get(i).getGenre() == 1)
                title = title + info.get(i).getTitle()+ "    ";
            }
            return title;
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wyxq_activity);
        ButterKnife.bind(this);
        hasIntent();
        initView();
    }

    private void hasIntent() {
        ywbqglBean = (YWGLBean) getIntent().getSerializableExtra("data");
        title = ywbqglBean.getTitle();
    }

    private void initView() {
        ywxqNoButtonBc.setVisibility(View.GONE);
        ywxqNoTextTitle.setText(title);
        ywxqNoEditXgms.setHint("暂无相关描述");
        ywxqNoEditXgms.setInputType(InputType.TYPE_NULL);
        ywxqNoEditXgms.setText(ywbqglBean.getDescribe());

        initRecyclerviewf();
    }

    private void initRecyclerviewf() {
        ywxqNoRecyclerview.setLayoutManager(new LinearLayoutManager(this));
        BaseAdapter<YWGLBean.NextBeanX> adapter = new BaseAdapter<YWGLBean.NextBeanX>(this,ywbqglBean.getNext()) {
            @Override
            public void convert(int position, BaseViewHolder holder, final YWGLBean.NextBeanX nextBeanX) {
                ((TextView)holder.getView(R.id.textView166)).setText(nextBeanX.getTitle());
                info.clear();
                info.addAll(nextBeanX.getNext());
                if (!TextUtils.isEmpty(info.toString().trim())){
                    ((TextView)holder.getView(R.id.textView167)).setText(info.toString());
                }else{
                    if (nextBeanX.getGenre() == 1){
                        ((TextView)holder.getView(R.id.textView167)).setText("已选择");
                    }
                }

            }

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.view_cjywxq_item;
            }
        };
        ywxqNoRecyclerview.setAdapter(adapter);
    }

    @OnClick(R.id.ywxq_no_image_fh)
    public void onViewClicked() {
        finish();
    }
}
